#lang sicp
(define (make-joint account password new-password)
  (define (new-account pwd msg)
    (if (eq? pwd new-password)
        (account password msg)
        "incorrect password!"))
  (if (account password 'auth)
      new-account
      "incorrect password!"))

(define (make-account password balance)
  (define (account pwd msg)
    (if (eq? msg 'auth)
        (auth pwd)
        (if (eq? pwd password)
            (dispatch msg)
            "incorrect password!")))
  (define (auth pwd)
    (eq? pwd password))
  (define (dispatch msg)
    (cond ((eq? msg 'withdraw) withdraw)
          ((eq? msg 'deposit) deposit)
          ((eq? msg 'inquire) balance)
          (else
           (error "unkown message -- MAKE-ACCOUNT" msg))))
  (define (withdraw amount)
    (if (> amount balance)
        "insufficient balance!"
        (begin (set! balance (- balance amount))
               balance)))
  (define (deposit amount)
    (set! balance (+ balance amount))
    balance)
  account)

(define peter-account (make-account 'haha 100))
(define paul-account (make-joint peter-account 'haha 'ohgod))




(define v 1)
(define count 0)
(define (f signal)
  (define pre-v v)
  (cond ((= signal 0)
         (set! v 0))
        (else
         (set! v 1)))
  (set! count (+ 1 count))
  (if (odd? count)
      0
      pre-v))


(define ff
  (let ((first #t))
    (lambda (s)
      (define r 0)
      (if (and first (= s 1))
          (set! r 1))
      (set! first (not first))
      r)))